package weaver.interfaces.zwgk.action;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.zwgk.utils.InvokeHelper;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-09-12
 * @Description: 销售合同变更申请流程
 * @ModifyLog:
 **/

public class WeaChangeContractAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        RecordSet rs = new RecordSet();
        writeLog( ">>>>>>WeaChangeContractAction>>>>>" + requestid );
        String resultText = "";
        try {
            rs.executeQuery( "select * from " + tablename + " where requestid=?", requestid );
            rs.next();
            JSONObject jsonData = new JSONObject();
            jsonData.put( "companyCode", Util.null2String( rs.getString( "gsjigoubianma" ) ) );
            jsonData.put( "contractCode", Util.null2String( rs.getString( "htbhbgwb" ) ) );
            jsonData.put( "changedAmount", Util.null2String( rs.getString( "htje" ) ) );
            jsonData.put( "changedCurrency", Util.null2String( rs.getString( "bzwb" ) ) );
            jsonData.put( "changedExcRate", Util.null2String( rs.getString( "hl" ) ) );
            jsonData.put( "effectiveDate", Util.null2String( rs.getString( "kssj" ) ) );
            jsonData.put( "createBy", Util.null2String( rs.getString( "sqrwb" ) ) );
            jsonData.put( "contractStatus", Util.null2String( rs.getString( "htzt" ) ) );
            jsonData.put( "tenantCode", Util.null2String( rs.getString( "zhbm" ) ) );
            jsonData.put( "status", "rkz" );
            writeLog( ">>>>>>jsonData>>>>>" + jsonData.toJSONString() );
            resultText = InvokeHelper.addChangeSellcont( jsonData.toJSONString() );
            writeLog( ">>>>>>resultText>>>>>" + resultText );
            JSONObject resultJson = JSONObject.parseObject( resultText );
            String code = Util.null2String( resultJson.getString( "code" ) );
            String message = Util.null2String( resultJson.getString( "message" ) );
            if (!"200".equals( code )) {
                requestInfo.getRequestManager().setMessageid( "111111" );
                requestInfo.getRequestManager().setMessagecontent( "接口返回异常信息：" + message );
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }

    }
}
